using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;

namespace Entity
{
	/// <summary>
	/// This object represents the Private Fields of TblProductReview.
	/// </summary>
	
	[System.ComponentModel.DataObject]
    public partial class TblProductReview : DatabaseUtility
    {
		#region TblProductReview Private Fields


		Int32 _productReviewId;
		Int32 _productId;
		String _customerName = String.Empty;
		String _customerEmail = String.Empty;
		Decimal? _ratingValue;
		String _reviewText = String.Empty;
		DateTime? _reviewDate;
		Boolean? _isApproved;
		
		#endregion
		#region TblProductReview Constractor
		/// <summary>
        /// Creates an empty object of TblProductReview. 
        /// This is mainly used to create a new instance of TblProductReview to add a new TblProductReview.
        /// </summary>
		public TblProductReview(){}
		
				
		/// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing TblProductReview.
        /// </summary>
		public TblProductReview
		(
			
			Int32 productReviewId,
			
			Int32 productId,
			
			String  customerName,
			
			String  customerEmail,
			
			Decimal? ratingValue,
			
			String  reviewText,
			
			DateTime? reviewDate,
			
			Boolean? isApproved
		)
		{
			_productReviewId = productReviewId;	
			_productId = productId;	
			_customerName = customerName;	
			_customerEmail = customerEmail;	
			_ratingValue = ratingValue;	
			_reviewText = reviewText;	
			_reviewDate = reviewDate;	
			_isApproved = isApproved;	
		}
		
		#endregion
		#region TblProductReview Properties
		
		 /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the ProductReviewId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_TblProductReview to update the data of an another TblProductReview instance.
        /// For view or updation purpose, every TblProductReview will be retrieved thru the proper 'Get' method.
        /// </summary>
		
		public Int32  ProductReviewId
		{
			get {return _productReviewId;}	
		}
		
				
		public Int32  ProductId
		{
			get {return _productId;}
			set {_productId = value;}
		}

		public String  CustomerName
		{
			get {return _customerName;}
			set {_customerName = value;}
		}

		public String  CustomerEmail
		{
			get {return _customerEmail;}
			set {_customerEmail = value;}
		}

		public Decimal?  RatingValue
		{
			get {return _ratingValue;}
			set {_ratingValue = value;}
		}

		public String  ReviewText
		{
			get {return _reviewText;}
			set {_reviewText = value;}
		}

		public DateTime?  ReviewDate
		{
			get {return _reviewDate;}
			set {_reviewDate = value;}
		}

		public Boolean?  IsApproved
		{
			get {return _isApproved;}
			set {_isApproved = value;}
		}
		

		#endregion
		#region TblProductReview Static Methods
		/************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
		/************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static  Int32 CreateNewTblProductReview
		(
			Int32 productId,
			String customerName,
			String customerEmail,
			Decimal? ratingValue,
			String reviewText,
			DateTime? reviewDate,
			Boolean isApproved
		)
		{
			//creating an empty TblProductReview object
            TblProductReview tblProductReview = new TblProductReview();
				tblProductReview.ProductId = productId;
				tblProductReview.CustomerName = customerName;
				tblProductReview.CustomerEmail = customerEmail;
				tblProductReview.RatingValue = ratingValue;
				tblProductReview.ReviewText = reviewText;
				tblProductReview.ReviewDate = reviewDate;
				tblProductReview.IsApproved = isApproved;
			
			return TblProductReview.CreateNewTblProductReview(tblProductReview);
		}
	
		/************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool UpdateTblProductReview
		(
			Int32 productReviewId,
			Int32 productId,
			String customerName,
			String customerEmail,
			Decimal? ratingValue,
			String reviewText,
			DateTime? reviewDate,
			Boolean isApproved
		)
		{
			 TblProductReview tblProductReview =  TblProductReview.GetTblProductReviewByProductReviewId(productReviewId);
			
				tblProductReview.ProductId = productId;
				tblProductReview.CustomerName = customerName;
				tblProductReview.CustomerEmail = customerEmail;
				tblProductReview.RatingValue = ratingValue;
				tblProductReview.ReviewText = reviewText;
				tblProductReview.ReviewDate = reviewDate;
				tblProductReview.IsApproved = isApproved;
			
			return TblProductReview.UpdateTblProductReview(tblProductReview);
		}

		/************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool DeleteTblProductReview
		(
			Int32 productReviewId
		)
		{
			//Validate Input
			if(productReviewId <= GetProductReviewIdMinValue)
				throw (new ArgumentOutOfRangeException("productReviewId"));
				
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
			               AddParameterToSqlCmd(sqlCmd, "@ProductReviewId",SqlDbType.Int, 0, ParameterDirection.Input, productReviewId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_DELETETBLPRODUCTREVIEW);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
			
		}
		
		/// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
		public static bool DeleteTblProductReviewList( System.Collections.Generic.List<Int32 >  productReviewIdListToDelete)
		{
			//Validate Input
			foreach (Int32 productReviewId in productReviewIdListToDelete)
			    if(productReviewId <= GetProductReviewIdMinValue)
					throw (new ArgumentOutOfRangeException("productReviewId"));
			
			//performing deletion operation //

            string xmlString = FormatXMLForIdArray(productReviewIdListToDelete);
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@ProductReviewIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_DELETETBLPRODUCTREVIEWLIST);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == productReviewIdListToDelete.Count ? true : false);
		}
		
		/************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
		public static TblProductReview GetTblProductReviewByProductReviewId(Int32 productReviewId)
		{
			if(productReviewId <= GetProductReviewIdMinValue)
					throw (new ArgumentOutOfRangeException("productReviewId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			               AddParameterToSqlCmd(sqlCmd, "@ProductReviewId",SqlDbType.Int, 0, ParameterDirection.Input, productReviewId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTREVIEWID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
		}
		
		/************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/
				
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
		public static CustomCollection<TblProductReview> GetTblProductReviewByProductId(Int32 productId)
		{
			if(productId <= GetProductIdMinValue)
					throw (new ArgumentOutOfRangeException("productId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			               AddParameterToSqlCmd(sqlCmd, "@ProductId",SqlDbType.Int, 0, ParameterDirection.Input, productId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection;
            else
                return null;
		}
		
		/// <summary>
        /// Gets all the TblProductReview regarding 'PREFERRED_LANGUAGE_ID' foreign key.
        /// It supports efficient paging.
        /// </summary>
        /// <returns>A collection of TblProductReview.</returns>
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public static CustomCollection<TblProductReview> GetTblProductReviewByProductIdPaged(Int32 productId,String orderBy, Int32 startRowIndex, Int32 maximumRows)
		{
            //Validate Input
			if(productId <= GetProductIdMinValue)
					throw (new ArgumentOutOfRangeException("productId"));
			
            if (orderBy == "")
                orderBy = "ProductId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			               AddParameterToSqlCmd(sqlCmd, "@ProductId",SqlDbType.Int, 0, ParameterDirection.Input, productId);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTIDPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
        }
		
		/// <summary>
        /// This is a supporting method of 'GetEmployeeByPREFERRED_LANGUAGE_IDPagedPagedCountPaged' method.
        /// Used in paging, which returns the total number of records, returned from the ''GetEmployeeByReportsToPaged'' method (regardless of page size).
        /// Although we are not using the parameters, but we need the same signature as ''GetEmployeeByReportsToPaged'' to support paging.
        /// </summary>
		public static int GetTblProductReviewByProductIdPagedCount(Int32 productId,String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
			if(productId <= GetProductIdMinValue)
					throw (new ArgumentOutOfRangeException("productId"));
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			               AddParameterToSqlCmd(sqlCmd, "@ProductId",SqlDbType.Int, 0, ParameterDirection.Input, productId);
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTIDPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		/************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblProductReview> GetAllTblProductReview()
		{
		
		 	// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETALLTBLPRODUCTREVIEW);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
		}
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblProductReview> GetAllTblProductReviewPaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "ProductReviewId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETALLTBLPRODUCTREVIEWPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblProductReviewPagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_GETALLTBLPRODUCTREVIEWPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		#endregion
		#region Employee Instance Methods
		/************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
		/// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
		public bool Save()
		{
			if(ProductReviewId<= GetProductReviewIdMinValue)
			{
				Int32  TempId=CreateNewTblProductReview(this);
				if(TempId>0)
				{
					_productReviewId=TempId;
					return true;
				}
				else
				{
					// error occurs
					return false;
				}
			}
			else
			{	//This is a update Command
				return (UpdateTblProductReview(this));
			}
			
		}
		
		public static Int32  CreateNewTblProductReview(TblProductReview newTblProductReview)
		{
			// validate Parameters
			if (newTblProductReview == null)
				throw (new ArgumentNullException("newTblProductReview"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			               AddParameterToSqlCmd(sqlCmd, "@ProductId",SqlDbType.Int, 0, ParameterDirection.Input, newTblProductReview.ProductId);
			if ( newTblProductReview.CustomerName!=null)
               AddParameterToSqlCmd(sqlCmd, "@CustomerName",SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblProductReview.CustomerName);
            else
               AddParameterToSqlCmd(sqlCmd, "@CustomerName",SqlDbType.NVarChar, 100, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.CustomerEmail!=null)
               AddParameterToSqlCmd(sqlCmd, "@CustomerEmail",SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblProductReview.CustomerEmail);
            else
               AddParameterToSqlCmd(sqlCmd, "@CustomerEmail",SqlDbType.NVarChar, 100, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.RatingValue!=null)
               AddParameterToSqlCmd(sqlCmd, "@RatingValue",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblProductReview.RatingValue);
            else
               AddParameterToSqlCmd(sqlCmd, "@RatingValue",SqlDbType.Decimal, 9, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.ReviewText!=null)
               AddParameterToSqlCmd(sqlCmd, "@ReviewText",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblProductReview.ReviewText);
            else
               AddParameterToSqlCmd(sqlCmd, "@ReviewText",SqlDbType.NVarChar, -1, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.ReviewDate!=null)
               AddParameterToSqlCmd(sqlCmd, "@ReviewDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblProductReview.ReviewDate);
            else
               AddParameterToSqlCmd(sqlCmd, "@ReviewDate",SqlDbType.DateTime, 0, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.IsApproved!=null)
               AddParameterToSqlCmd(sqlCmd, "@IsApproved",SqlDbType.Bit, 0, ParameterDirection.Input, newTblProductReview.IsApproved);
            else
               AddParameterToSqlCmd(sqlCmd, "@IsApproved",SqlDbType.Bit, 0, ParameterDirection.Input ,System.DBNull.Value);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_CREATENEWTBLPRODUCTREVIEW);
			ExecuteScalarCmd(sqlCmd);
			return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

		}
		/// <summary>
        /// Updates an TblProductReview instance to the database.
        /// </summary>
		public static bool UpdateTblProductReview(TblProductReview newTblProductReview)
		{
			// validate Parameters
			if (newTblProductReview == null)
				throw (new ArgumentNullException("newTblProductReview"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			               AddParameterToSqlCmd(sqlCmd, "@ProductReviewId",SqlDbType.Int, 0, ParameterDirection.Input, newTblProductReview.ProductReviewId);
			               AddParameterToSqlCmd(sqlCmd, "@ProductId",SqlDbType.Int, 0, ParameterDirection.Input, newTblProductReview.ProductId);
			if ( newTblProductReview.CustomerName!=null)
               AddParameterToSqlCmd(sqlCmd, "@CustomerName",SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblProductReview.CustomerName);
            else
               AddParameterToSqlCmd(sqlCmd, "@CustomerName",SqlDbType.NVarChar, 100, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.CustomerEmail!=null)
               AddParameterToSqlCmd(sqlCmd, "@CustomerEmail",SqlDbType.NVarChar, 100, ParameterDirection.Input, newTblProductReview.CustomerEmail);
            else
               AddParameterToSqlCmd(sqlCmd, "@CustomerEmail",SqlDbType.NVarChar, 100, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.RatingValue!=null)
               AddParameterToSqlCmd(sqlCmd, "@RatingValue",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblProductReview.RatingValue);
            else
               AddParameterToSqlCmd(sqlCmd, "@RatingValue",SqlDbType.Decimal, 9, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.ReviewText!=null)
               AddParameterToSqlCmd(sqlCmd, "@ReviewText",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblProductReview.ReviewText);
            else
               AddParameterToSqlCmd(sqlCmd, "@ReviewText",SqlDbType.NVarChar, -1, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.ReviewDate!=null)
               AddParameterToSqlCmd(sqlCmd, "@ReviewDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblProductReview.ReviewDate);
            else
               AddParameterToSqlCmd(sqlCmd, "@ReviewDate",SqlDbType.DateTime, 0, ParameterDirection.Input ,System.DBNull.Value);
			if ( newTblProductReview.IsApproved!=null)
               AddParameterToSqlCmd(sqlCmd, "@IsApproved",SqlDbType.Bit, 0, ParameterDirection.Input, newTblProductReview.IsApproved);
            else
               AddParameterToSqlCmd(sqlCmd, "@IsApproved",SqlDbType.Bit, 0, ParameterDirection.Input ,System.DBNull.Value);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLPRODUCTREVIEW_UPDATETBLPRODUCTREVIEW);
            ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
		}
		#endregion
		
		#region TblProductReview Related Collections
		/// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
		public static CollectionBase  GenerateTblProductReviewCollectionFromReader(IDataReader returnData) 
		{
			
			//creating the instance of Employee collection
			CustomCollection<TblProductReview> colTblProductReview = new CustomCollection<TblProductReview>();
			
			Boolean? null_Boolean=null;
			Int32? null_Int32=null;
			Int16? null_Int16=null;
			Decimal? null_Decimal=null;
			DateTime? null_DateTime=null;
			Int64? null_Int64=null;
			Double? null_Double=null;
			/************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

			//getting the Employee collection by iterating thru the data reader
			while (returnData.Read()) 
			{
				//passing the TblProductReview constructor parameters from the current instance of data reader fields.
				TblProductReview newTblProductReview = new TblProductReview
				(
					returnData["ProductReviewId"]== System.DBNull.Value ? GetProductReviewIdMinValue : (Int32) returnData["ProductReviewId"],
					returnData["ProductId"]== System.DBNull.Value ? 0: (Int32 ) returnData["ProductId"],
					returnData["CustomerName"]== System.DBNull.Value ? string.Empty: (String ) returnData["CustomerName"],
					returnData["CustomerEmail"]== System.DBNull.Value ? string.Empty: (String ) returnData["CustomerEmail"],
					returnData["RatingValue"]== System.DBNull.Value ? null_Decimal: (Decimal ) returnData["RatingValue"],
					returnData["ReviewText"]== System.DBNull.Value ? string.Empty: (String ) returnData["ReviewText"],
					returnData["ReviewDate"]== System.DBNull.Value ? null_DateTime: (DateTime ) returnData["ReviewDate"],
					returnData["IsApproved"]== System.DBNull.Value ? null_Boolean: (Boolean ) returnData["IsApproved"]

				);
				//adding the Employee to the collection
				colTblProductReview.Add(newTblProductReview);
			}
			
			//returns the collection of Companys 
			return (colTblProductReview);
		}
		
		#endregion
		#region Constants and Default Values
		
		public static Int32  GetProductReviewIdMinValue
		{
			get
			{
				return 0;
			}
		}
		public static Int32  GetProductIdMinValue
		{
			get
			{
				return 0;
			}
		}
		
		//create method related contants
			internal const string SPR_TBLPRODUCTREVIEW_CREATENEWTBLPRODUCTREVIEW="spr_TblProductReview_CreateNewTblProductReview";
			internal const string SPR_TBLPRODUCTREVIEW_UPDATETBLPRODUCTREVIEW="spr_TblProductReview_UpdateTblProductReview";
			internal const string SPR_TBLPRODUCTREVIEW_DELETETBLPRODUCTREVIEW="spr_TblProductReview_DeleteTblProductReview";
			internal const string SPR_TBLPRODUCTREVIEW_DELETETBLPRODUCTREVIEWLIST="spr_TblProductReview_DeleteTblProductReviewList";
			internal const string SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTREVIEWID="spr_TblProductReview_GetTblProductReviewByProductReviewId";
			internal const string SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTID="spr_TblProductReview_GetTblProductReviewByProductId";
			internal const string SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTIDPAGED="spr_TblProductReview_GetTblProductReviewByProductIdPaged";
			internal const string SPR_TBLPRODUCTREVIEW_GETTBLPRODUCTREVIEWBYPRODUCTIDPAGEDCOUNT="spr_TblProductReview_GetTblProductReviewByProductIdPagedCount";
			internal const string SPR_TBLPRODUCTREVIEW_GETALLTBLPRODUCTREVIEW="spr_TblProductReview_GetAllTblProductReview";
			internal const string SPR_TBLPRODUCTREVIEW_GETALLTBLPRODUCTREVIEWPAGED="spr_TblProductReview_GetAllTblProductReviewPaged";
			internal const string SPR_TBLPRODUCTREVIEW_GETALLTBLPRODUCTREVIEWPAGEDCOUNT="spr_TblProductReview_GetAllTblProductReviewPagedCount";
		
		#endregion
	}
}	
